

//校驗是否是數字，傳入object的id
function isNum(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if ("" == s){
		return true;
	} 
	if (isNaN(s)) {
		//object.value = "";
		alert(popMsg);
		object.focus();
		return false;
	}
	return true;
}

//校驗是否是數字，傳入object的id，可以為空
function isNumCanNull(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if ("" == s){
		return true;
	} 
	if(isNaN(s)) {
		//object.value = "";
		alert(popMsg);
		object.focus();
		return false;
	}
	return true;
}
//可以為數字和","
function isNumCanNull1(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	var pattern = /^[0-9,\-]*$/;
	if ("" != s) {
		if (!pattern.exec(s)) {
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}

//校验普通电话、传真号码：可以“+”开头，除数字外，可含有“-”
function isTel(id, popMsg) {
//国家代码(2到3位)-区号(2到3位)-电话号码(7到8位)-分机号(3位)" 
	var object = document.getElementById(id);
	var s = object.value;
	var pattern = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
	if ("" != s) {
		if (!pattern.exec(s)) {
			alert(popMsg);
			//object.value = "";
			object.focus();
			return false;
		}
	}
	return true;
}
function isTelforTW(id, popMsg){
	var object = document.getElementById(id);
	var s = object.value;
	var pattern = /^[0-9\-\# ]*$/;
	if ("" != s) {
		if (!pattern.exec(s)) {
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}

//校驗海外電話，可以輸入數字或"-"
function isOutseaTel(id, popMsg) {
//包含4碼國家代號+14碼電話號碼 
	var object = document.getElementById(id);
	var s = object.value;
	alert(s)
	var pattern = /^[0-9\-][0-9]$/;
	alert(pattern.exec(s))
	if ("" != s) {
		if (!pattern.exec(s)) {
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}
//校驗email
function isEmail(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	var pattern = /^[a-zA-Z0-9_\-.]{1,}@[a-zA-Z0-9_\-]{1,}\.[a-zA-Z0-9_\-.]{1,}$/;
	if ("" != s) {
		if (!pattern.exec(s)) {
			//object.value = "";
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}

//校验手机号码：必须以数字开头，除数字外，可含有“-”   
function isMobile(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	var reg0 = /^13\d{5,9}$/;
	var reg1 = /^153\d{4,8}$/;
	var reg2 = /^159\d{4,8}$/;
	var reg3 = /^0\d{10,11}$/;
	var my = false;
	if (reg0.test(s)) {
		my = true;
	}
	if (reg1.test(s)) {
		my = true;
	}
	if (reg2.test(s)) {
		my = true;
	}
	if (reg3.test(s)) {
		my = true;
	}
	if ("" != s) {
		if (!my) {
			//object.value = "";
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}
//校验(国内)邮政编码   
function isPostalCode(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	var pattern = /^[0-9]{6}$/;
	if ("" != s) {
		if (!pattern.exec(s)) {
			//object.value = "";
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}
//校验日期  2009-01-01 或 2009/01/01或20090101 是正確格式
//並把input欄位的值改為yyyy/MM/dd格式 
function isDate(id,popMsg){
var object = document.getElementById(id);
	var s = object.value;
	var result1 = s.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(\/)(10|12|0?[13578])(\/)(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(\/)(11|0?[469])(\/)(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(\/)(0?2)(\/)(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)(\/)(0?2)(\/)(29)$)|(^([3579][26]00)(\/)(0?2)(\/)(29)$)|(^([1][89][0][48])(\/)(0?2)(\/)(29)$)|(^([2-9][0-9][0][48])(\/)(0?2)(\/)(29)$)|(^([1][89][2468][048])(\/)(0?2)(\/)(29)$)|(^([2-9][0-9][2468][048])(\/)(0?2)(\/)(29)$)|(^([1][89][13579][26])(\/)(0?2)(\/)(29)$)|(^([2-9][0-9][13579][26])(\/)(0?2)(\/)(29)$))/);
	var result2 = s.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(-)(10|12|0?[13578])(-)(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(11|0?[469])(-)(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(0?2)(-)(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)(-)(0?2)(-)(29)$)|(^([3579][26]00)(-)(0?2)(-)(29)$)|(^([1][89][0][48])(-)(0?2)(-)(29)$)|(^([2-9][0-9][0][48])(-)(0?2)(-)(29)$)|(^([1][89][2468][048])(-)(0?2)(-)(29)$)|(^([2-9][0-9][2468][048])(-)(0?2)(-)(29)$)|(^([1][89][13579][26])(-)(0?2)(-)(29)$)|(^([2-9][0-9][13579][26])(-)(0?2)(-)(29)$))/);         
    var result3 = s.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(10|12|0[13578])(3[01]|[12][0-9]|0[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(11|0[469])(30|[12][0-9]|0[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(02)(2[0-8]|1[0-9]|0[1-9])$)|(^([2468][048]00)(02)(29)$)|(^([3579][26]00)(02)(29)$)|(^([1][89][0][48])(02)(29)$)|(^([2-9][0-9][0][48])(02)(29)$)|(^([1][89][2468][048])(02)(29)$)|(^([2-9][0-9][2468][048])(02)(29)$)|(^([1][89][13579][26])(02)(29)$)|(^([2-9][0-9][13579][26])(02)(29)$))/);
	if ("" != object) {
		if(result1!=null){
			object.value = composeCalendar(s,"\/");
		}else if(result2!=null){
			object.value = composeCalendar(s,"-");
		}else if(result3!=null){
			object.value = s.substring(0,4)+"\/"+s.substring(4,6)+"\/"+s.substring(6,8);
		}else{
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}

//校验日期  2009-01 或 2009/01或200901 是正確格式
//並把input欄位的值改為yyyy/MM格式 
function isDateyyyyMM(id,popMsg){
	var object = document.getElementById(id);
	var s = object.value;
	var result1 = s.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(\/)(10|12|0?[13578])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(\/)(11|0?[469])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(\/)(0?2)$)|(^([2468][048]00)(\/)(0?2)$)|(^([3579][26]00)(\/)(0?2)$)|(^([1][89][0][48])(\/)(0?2)$)|(^([2-9][0-9][0][48])(\/)(0?2)$)|(^([1][89][2468][048])(\/)(0?2)$)|(^([2-9][0-9][2468][048])(\/)(0?2)$)|(^([1][89][13579][26])(\/)(0?2)$)|(^([2-9][0-9][13579][26])(\/)(0?2)$))/);
	var result2 = s.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(-)(10|12|0?[13578])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(11|0?[469])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(0?2)$)|(^([2468][048]00)(-)(0?2)$)|(^([3579][26]00)(-)(0?2)$)|(^([1][89][0][48])(-)(0?2)$)|(^([2-9][0-9][0][48])(-)(0?2)$)|(^([1][89][2468][048])(-)(0?2)$)|(^([2-9][0-9][2468][048])(-)(0?2)$)|(^([1][89][13579][26])(-)(0?2)$)|(^([2-9][0-9][13579][26])(-)(0?2)$))/);         
    var result3 = s.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(10|12|0?[13578])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(11|0?[469])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(0?2)$)|(^([2468][048]00)(0?2)$)|(^([3579][26]00)(0?2)$)|(^([1][89][0][48])(0?2)$)|(^([2-9][0-9][0][48])(0?2)$)|(^([1][89][2468][048])(0?2)$)|(^([2-9][0-9][2468][048])(0?2)$)|(^([1][89][13579][26])(0?2)$)|(^([2-9][0-9][13579][26])(0?2)$))/);         
	if ("" != object) {
		if(result1!=null){
			object.value = composeYYYYMM(s,"\/");
		}else if(result2!=null){
			object.value = composeYYYYMM(s,"-");
		}else if(result3!=null){
			object.value = s.substring(0,4)+"\/"+s.substring(4,6);
		}else{
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}

function composeCalendar(ca,delimiter){
	var idx = ca.indexOf(delimiter);
	var len = ca.length; 
	var year = ca.substring(0,idx);
	ca = ca.substring(idx+1,len);
	idx = ca.indexOf(delimiter);
	var month = ca.substring(0,idx);
	var day = ca.substring(idx+1,len);
	if(month.length<2){
		month = "0"+month;
	}
	if(day.length<2){
		day = "0"+day;
	}
	return year+"\/"+month+"\/"+day;
}

function composeYYYYMM(ca,delimiter){
	var idx = ca.indexOf(delimiter);
	var len = ca.length; 
	var year = ca.substring(0,idx);
	month = ca.substring(idx+1,len);
	if(month.length<2){
		month = "0"+month;
	}
	return year+"\/"+month;
}
//校驗時間是，hhss 12:01  1201都是正確的
//校驗後時間格式變為hh:ss
function isHHSS(id,popMsg){
	var object = document.getElementById(id);
	var s = object.value;
	if(s!=null && ""!=s) {
		var result1 = s.match(/((^(0|1)[0-9][0-5][0-9]$)|(^2[0-3][0-5][0-9]$)|(^(0|1)[0-9]:[0-5][0-9]$)|(^2[0-3]:[0-5][0-9]$))/);
		if(result1!=null){
			if(s.length == 4){
				object.value = s.substring(0,2)+":"+s.substring(2,4);
			}
			return true;
		}else{
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}
//校驗後時間格式變為hhmm
function isHHMM(id,popMsg){
	var object = document.getElementById(id);
	var s = object.value;
	if(s!=null && ""!=s) {
		var result1 = s.match(/((^(0|1)[0-9][0-5][0-9]$)|(^2[0-3][0-5][0-9]$)|(^(0|1)[0-9]:[0-5][0-9]$)|(^2[0-3]:[0-5][0-9]$))/);
		if(result1!=null){
			return true;
		}else{
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}
//校驗時間是，HHmmss 12:01:01  120101都是正確的
//校驗後時間格式變為HH:mm:ss
function isHHmmss(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if(s!=null && ""!=s) {
		var result1 = s.match(/((^(0|1)[0-9][0-5][0-9][0-5][0-9]$)|(^2[0-3][0-5][0-9][0-5][0-9]$)|(^(0|1)[0-9]:[0-5][0-9]:[0-5][0-9]$)|(^2[0-3]:[0-5][0-9]:[0-5][0-9]$))/);
		if(result1!=null){
			if(s.length == 6){
				object.value = s.substring(0,2)+":"+s.substring(2,4) + ":" + s.substring(4,6);
			}
			return true;
		}else{
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}
//檢核輸入值不得大於系統日
function isSystemDate(id,popMsg){
	var object = document.getElementById(id);
	var s = object.value;
	var myDate  = new Date(); 
	var yy = myDate.getYear() +""; 
	var mm = myDate.getMonth() + 1+"";
	var dd = myDate.getDate()+""; 
	if(mm.length<2){
		mm="0"+mm;
	}
	if(dd.length<2){
		dd="0"+dd;
	}
	
	var nowDateFormat=yy+"/"+mm+"/"+dd;
	if(s!=null && ""!=s) {
		if(s <= nowDateFormat){
			return true;
		}else{
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}
//檢核輸入值不得大於系統日yyyy/MM
function isSystemDateYYYYMM(id,popMsg){
	var object = document.getElementById(id);
	var s = object.value;
	var myDate  = new Date(); 
	var yy = myDate.getYear() +""; 
	var mm = myDate.getMonth() + 1+"";
	if(mm.length<2){
		mm="0"+mm;
	}
	var nowDateFormat=yy+"/"+mm;
	if(s!=null && ""!=s) {
		if(s <= nowDateFormat){
			return true;
		}else{
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}
//檢核輸入值a不得大於b
function isSystemDate(id1,id2,popMsg){
	var object1 = document.getElementById(id1);
	var object2 = document.getElementById(id2);
	var s1 = object1.value;
	var s2 = object2.value;
	if(s1!=null && ""!=s1 && s2!=null && ""!=s2) {
		if(s1 <= s2){
			return true;
		}else{
			alert(popMsg);
			object.focus();
			return false;
		}
	}
	return true;
}
//不能為空
function dateNotEmpty(value, popMsg){
	var patrn= /.*\s+.*/;
	if (patrn.exec(value) || value == ''){
		alert(popMsg);
	 	return false; 
	}else{
		return true;
	} 
}
//校驗欄位長度不能大於len
function checklength(id, len, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ""){
		return true;
	}
	if ("" != s) {
		var i, l = 0;
		for (i = 0; i < s.length; i++) {
			if (s.charCodeAt(i) > 127) {
				l += 2;
			} else {
				l++;
			}
		}
		if (l > len) {
			object.focus();
			alert(popMsg);
			return false;
		}
	}
	return true;
}
//校驗欄位長度不能大於len,中文字算一個長度（因為DB中用nvarchar）
function checklengthNvarchar(id, len, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ""){
		return true;
	}
	if ("" != s) {
		var i, l = 0;
		l = s.length;
		if (l > len) {
			object.focus();
			alert(popMsg);
			return false;
		}
	}
	return true;
}
//校驗欄位長度不能小於len
function checklength1(id, len, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ""){
		return true;
	}
	if ("" != s) {
		var i, l = 0;
		for (i = 0; i < s.length; i++) {
			if (s.charCodeAt(i) > 127) {
				l += 2;
			} else {
				l++;
			}
		}
		if (l < len) {
			object.focus();
			alert(popMsg);
			return false;
		}
	}
	return true;
}

//校驗欄位長度不能大於len，可以为空
function checklengthnotnull(id, len, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ""){
		return true;
	}
	if ("" != s) {
		var i, l = 0;
		for (i = 0; i < s.length; i++) {
			if (s.charCodeAt(i) > 127) {
				l += 2;
			} else {
				l++;
			}
		}
		if (l > len) {
			object.focus();
			alert(popMsg);
			return false;
		}
	}
	return true;
}

//校驗欄位長度不能小於len
function checklengthnotLt(id, len, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if ("" != s) {
		var i, l = 0;
		for (i = 0; i < s.length; i++) {
			if (s.charCodeAt(i) > 127) {
				l += 2;
			} else {
				l++;
			}
		}
		if (l < len) {
			object.focus();
			alert(popMsg);
			return false;
		}
	}
	return true;
}

//校驗欄位長度不能小於len，可以為空
function checklengthnotLtnotnull(id, len, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ""){
		return true;
	}
	if ("" != s) {
		var i, l = 0;
		for (i = 0; i < s.length; i++) {
			if (s.charCodeAt(i) > 127) {
				l += 2;
			} else {
				l++;
			}
		}
		if (l < len) {
			object.focus();
			alert(popMsg);
			return false;
		}
	}
	return true;
}
//校驗電話區域號碼範圍
function checkPhoneArea(id,popMsg){
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ""){
		return true;
	}
	if ("" != s) {		
		if (s.length ==  '2') {	
			if (s!=  '02'&& s!='03'&& s!='04'&&s!='05'&&s!='06'
				&&s!='07'&& s!='08') {
				object.focus();
				alert(popMsg);
				return false;
			}
		}else if(s.length ==  '3'){
			if (s!=  '037'&& s!='049'&& s!='082'&&s!='083'&&s!='089'
				&&s!='070') {
				object.focus();
				alert(popMsg);
				return false;
			}		
		}else if(s.length ==  '1'){
				object.focus();
				alert(popMsg);
				return false;		
		}
	}	
	return true;		
}
//校驗欄位長度等於len
function equallength(id, len, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
		if (s.length !=  len) {
			object.focus();
			alert(popMsg);
			return false;
		}
	return true;
}
//校驗欄位長度等於len，值為空時，不判斷
function equallength1(id, len, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if(s!="") {
		if (s.length !=  len) {
			object.focus();
			alert(popMsg);
			return false;
		}
	}
	return true;
}
//判断数字与范围，小時為[0~24]的數值資料 
function checkNumHour(id,popMsg){ 
	if(!isNum(id,popMsg)){
		return false;
	}
	var object = document.getElementById(id);
	var s = object.value;
	if(s!=""){
		s = trimVal(s);
		s = parseInt(s);
		if(s >= 0 && s <= 24){ 
			return true;
		}else{
			alert(popMsg);
			object.focus();
			return false;
		} 
	} 
	return true;
}
  		
//判断数字与范围，分為[0~59]的數值資料 
function checkNumMinute(id,popMsg){ 
	if(!isNum(id,popMsg)){
		return false;
	}
	var object = document.getElementById(id);
	var s = object.value;
	if(s!=""){ 
		s = trimVal(s);
		s = parseInt(s);
		if(s >= 0 && s <= 59){ 
			return true;
		}else{
			alert(popMsg);
			object.focus();
			return false;
		} 
	} 
	return true;
}
  		
//判斷身份證號碼，必須是以字母開頭，從第二位開始為數字
function isIdentityCard(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ""){
		return true;
	}
	var patrn=/^[a-zA-Z]{1}[0-9]*$/
	
	if (!patrn.exec(s)){
		alert(popMsg);
		object.focus();
	 	return false; 
	}else{
		return true;
	} 
} 

//必須是數字和字母，以字母開頭
function isAlphaNum(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ""){
		return true;
	}
	var patrn=/^[a-zA-Z]{1}[a-zA-Z0-9_]*$/
	if (!patrn.exec(s)){
		alert(popMsg);
		object.focus();
	 	return false; 
	}else{
		return true;
	} 
} 
//必須是數字和字母
function isAlphaNum2(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ""){
		return true;
	}
	var patrn=/^[a-zA-Z0-9_]*$/
	if (!patrn.exec(s)){
		alert(popMsg);
		object.focus();
	 	return false; 
	}else{
		return true;
	} 
} 
//必須是數字或數字與空格組合，不能為字母，以數字或空格開頭 
//對電話（公）格式為：02 87878818 2415  做判斷
function isNumAndSpace(id, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ""){
		return true;
	}
	var patrn=/^[0-9 ]{1}[0-9 ]*$/
	if (!patrn.exec(s)){
		alert(popMsg);
		object.focus();
	 	return false; 
	}else{
		return true;
	} 
} 		

//不能為空
function notEmpty(id, popMsg){
	var object = document.getElementById(id);
	var s = object.value;
	var flag = false;
	if(s != null) {
		s = trimVal(s);
		if(s == '') {
			flag = true; 
		}
	} else {
		flag = true;
	}
	if(flag) {
		alert(popMsg);
		object.focus();
	 	return false; 
	}
	return true;
}
//校验数字英文，可以为空
function isId1(id, popMsg)
{
	var object = document.getElementById(id);
	var s = object.value;
	var pattern = /^[A-Za-z0-9]+$/;
	if(s == ''){
		return true;
	}
	if (!pattern.exec(s)) {
		alert(popMsg);
		object.focus();
		return false;
	}	
	return true;
}

//校验是否标识符
function isId(id, popMsg)
{
	var object = document.getElementById(id);
	var s = object.value;
	//var pattern = /^[a-zA-Z][a-zA-Z0-9_]+$/;
	var pattern = /^[a-zA-Z0-9_]+$/;
	if (!pattern.exec(s)) {
		alert(popMsg);
		//object.value = "";
		object.focus();
		return false;
	}
	return true;
}
//校验是否合法名称
function isName(id, popMsg)
{
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ''){
		return true;
	}
	var pattern = /^[a-zA-Z0-9_\u0391-\uFFE5]+$/;
	if (!pattern.exec(s)) {
		alert(popMsg);
		//object.value = "";
		object.focus();
		return false;
	}
	return true;
}
//中文,英文,數字組合
function isName1(id, popMsg)
{
	var object = document.getElementById(id);
	var s = object.value;
	if(s == ''){
		return true;
	}
	var pattern = /^[\u4E00-\u9FA5A-Za-z0-9]+$/;
	if (!pattern.exec(s)) {
		alert(popMsg);
		//object.value = "";
		object.focus();
		return false;
	}
	return true;
}
//檢核時間不能大於當前時間，時間格式為yyyy/mm/dd
function compNowDate(id,popMsg)
{
	var object = document.getElementById(id);
	var s = object.value;
	var stoday = new Date(); 
	var syear = stoday.getYear().toString(); 
	var smonth = (stoday.getMonth()+1).toString(); 
	var sday = stoday.getDate().toString(); 
	if(smonth.length == 1) 
	{ 
	smonth = "0"+smonth; 
	} 
	if(sday.length == 1) 
	{ 
	sday = "0"+sday; 
	} 
	var strToday = syear+"/"+smonth+"/"+sday;
	if(s>strToday){
		alert(popMsg);
		object.focus();
		return false;
	}
	return true;
}

//檢核時間必須大於或等於當前時間，時間格式為yyyy/mm/dd
function compNowDate1(id,popMsg)
{
	var object = document.getElementById(id);
	var s = object.value;
	var stoday = new Date(); 
	var syear = stoday.getYear().toString(); 
	var smonth = (stoday.getMonth()+1).toString(); 
	var sday = stoday.getDate().toString(); 
	if(smonth.length == 1) 
	{ 
	smonth = "0"+smonth; 
	} 
	if(sday.length == 1) 
	{ 
	sday = "0"+sday; 
	} 
	var strToday = syear+"/"+smonth+"/"+sday;
	//alert(s+"  "+strToday)
	if(s<strToday){
		alert(popMsg);
		object.focus();
		return false;
	}
	return true;
}
//檢核時間不能大於當前時間，時間格式為yyyy/mm
function compNowYYYYMM(id,popMsg)
{
	var object = document.getElementById(id);
	var s = object.value;
	var stoday = new Date(); 
	var syear = stoday.getYear().toString(); 
	var smonth = (stoday.getMonth()+1).toString(); 
	if(smonth.length == 1) 
	{ 
	smonth = "0"+smonth; 
	} 
	var strToday = syear+"/"+smonth;
	if(s>strToday){
		alert(popMsg);
		object.focus();
		return false;
	}
	return true;
}

function compareExcludeSpace(popMsg,elementsId){
	var smallerId = elementsId[0];
	var biggerId = elementsId[1];
	var smallerObj = document.getElementById(smallerId);
	var biggerObj = document.getElementById(biggerId);
	if(smallerObj.value!=""&&biggerObj.value!=""
		&&smallerObj.value.length!=0&&biggerObj.value.length!=0){
		if(smallerObj.value.length>biggerObj.value.length)
		{
			alert(popMsg);
			return false;
		}
		if(smallerObj.value>biggerObj.value)
		{
			alert(popMsg);
			return false;
		}
	}
	return true;
}

function compareoneyear(popMsg,elementsId)
{
	var smallerId = elementsId[0];
	var biggerId = elementsId[1];
	var smallerObj = document.getElementById(smallerId);
	var biggerObj = document.getElementById(biggerId);
	var reg = new RegExp("/","g");
	var starttime = smallerObj.value.replace(reg , "");
	var endtime = biggerObj.value.replace(reg , "");
	if(endtime*1-starttime*1>10000){
		alert(popMsg);
		return false;
	}
	return true;
}

function compare(popMsg,elementsId)
{
	var smallerId = elementsId[0];
	var biggerId = elementsId[1];
	var smallerObj = document.getElementById(smallerId);
	var biggerObj = document.getElementById(biggerId);
	if(smallerObj.value.length>biggerObj.value.length)
	{
		alert(popMsg);
		return false;
	}
	if(smallerObj.value>biggerObj.value)
	{
		alert(popMsg);
		return false;
	}
	return true;
}
	
//校驗器，在jsp onload時，先push要校驗的訊息，當校驗時，做execute即可。
//push时,若为多校验则第一个参数输入为"M" or "m"
//当为单校验时参数依次为输入项ID,校验方法,弹出信息.长度选项可选,且需要传入大于0的数字.
//当为多校验时后续参数依次为弹出的错误信息

function Validator()
{
	//需要校验的ITEM
	this.arr = new Array();
	
	//执行校验方法
	var execute = function()
	{
		for(var index = 0;index< this.arr.length;index = index + 1)
		{
			var obj = this.arr[index];
			if( obj instanceof Item)
			{
				if(obj.len=="0")
				{
					if(!obj.method(obj.elementId,obj.popMsg))
						return false;
				}
				else
				{
					if(!obj.method(obj.elementId,obj.len,obj.popMsg))
						return false;
				}
			}
			else if( obj instanceof Compare)
			{
				if(!obj.method(obj.popMsg,obj.elementIds))
					return false;
			}
		}
		return true;
	}
	
	//单校验时
	//1.校验的输入项目ID
	//2.校验具体方法
	//3.弹出的错误信息
	//4.校验项目长度（可选）
	//多校验时
	//1."M"或"m"
	//2.弹出的错误信息
	//3.执行的方法
	//4.多个ELEMENTID
	var push = function()
	{
		var compareType = arguments[0];
		if(compareType=="M" || compareType=="m")
		{
			var popMsg = arguments[1];
			var method = arguments[2];
			var arrm = new Array();
			for(var index = 3;index < arguments.length;index = index + 1)
				arrm[arrm.length] = arguments[index];
			this.arr[this.arr.length] = new Compare(popMsg,method,arrm);
		}
		else
		{
			if(arguments.length==4)
				this.arr[this.arr.length] = new Item(arguments[0],arguments[1],arguments[2],arguments[3]);
			else if(arguments.length==3)
				this.arr[this.arr.length] = new Item(arguments[0],arguments[1],arguments[2],"0");
			else
				alert("您输入的参数个数只能为3或4,如该接口有任何问题请联系我");
		}
	}
	
	//移除校验规则
	//若为单校验,则参数为项目ID
	//若为多校验,则参数为较小的输入项目ID,较大的输入项目ID
	var pop = function()
	{	
		for(var index = 0;index< this.arr.length;)
		{
			var obj = this.arr.pop();
			if(obj instanceof Item && arguments.length==1)
			{
				if(obj.elementId==arguments[0])
					continue;
			}
			else if(obj instanceof Compare)
			{
				var flg = true;
				for(var i = 0;i < obj.elementIds.length; i = i + 1)
				if(obj.elementIds[i] != arguments[i]) flg = false;
				if(flg) continue;
			}
			index = index + 1;
			this.arr.unshift(obj);
		}
	}
	
	//校验实体
	function Item(elementId,method,popMsg,len)
	{
		this.elementId = elementId;
		this.method = method;
		this.popMsg = popMsg;
		this.len = len;
	}
	
	//多元素值比较器
	function Compare(popMsg,method,elementIds)
	{
		this.elementIds = elementIds;
		this.popMsg = popMsg;
		this.method = method;
	}
	
	this.push = push;
	this.pop = pop;
	this.execute = execute;
}

//去掉前后空白
function trimVal(val){
	if (!val) {
		return "";
	}
	return val.replace(/(^\s*)|(\s*$)/g,"");
}
//校驗數字必須大於等於給定值
function numberGE(id,num,popMsg){
	var object = document.getElementById(id);
	var s = object.value;
	if(s!=null && ""!=s) {
		if(parseInt(s)<parseInt(num)){
			alert(popMsg);
			return false;
		}else{
			return true;
		}
	}
	return true;
}
//校驗數字必須小於等於給定值
function numberLE(id,num,popMsg){
	var object = document.getElementById(id);
	var s = object.value;
	if(s!=null && ""!=s) {
		if(parseInt(s)>parseInt(num)){
			alert(popMsg);
			return false;
		}else{
			return true;
		}
	}
	return true;
}
//檢核若有多筆Email時，每筆Email格式是否正確（Email間以傳入的flag來作區隔）
function checkEmails(id, flag, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	var rtn = false;
	var pattern = /^[a-zA-Z0-9_\-.]{1,}@[a-zA-Z0-9_\-]{1,}\.[a-zA-Z0-9_\-.]{1,}$/;
	if(s!=null && ""!=s) {
		if(s.indexOf(flag) != -1) {
			var arr = s.split(flag);
			if(arr!=null && arr.length>0) {
				for(i=0; i<arr.length; i++) {
					if("" != arr[i]) {
						if (!pattern.exec(arr[i])) {
							rtn = true;
							break;
						}
					}
				}
				if(rtn) {
					alert(popMsg);
					object.focus();
					return false;
				}
			}
		} else {
			if (!pattern.exec(s)) {
				alert(popMsg);
				object.focus();
				return false;
			}
		}
	}
	return true;
}


function checkIps(id, flag, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	var rtn = false;
	var pattern = /^((\d)|(([1-9])\d)|(1\d\d)|(2(([0-4]\d)|5([0-5]))))\.((\d)|(([1-9])\d)|(1\d\d)|(2(([0-4]\d)|5([0-5]))))\.((\d)|(([1-9])\d)|(1\d\d)|(2(([0-4]\d)|5([0-5]))))\.((\d)|(([1-9])\d)|(1\d\d)|(2(([0-4]\d)|5([0-5]))))$/;
	if(s!=null && ""!=s) {
		if(s.indexOf(flag) != -1) {
			var arr = s.split(flag);
			if(arr!=null && arr.length>0) {
				for(i=0; i<arr.length; i++) {
					if("" != arr[i]) {
						if (!pattern.exec(arr[i])) {
							rtn = true;
							break;
						}
					}
				}
				if(rtn) {
					alert(popMsg);
					object.focus();
					return false;
				}
			}
		} else {
			if (!pattern.exec(s)) {
				alert(popMsg);
				object.focus();
				return false;
			}
		}
	}
	return true;
}

function checkServerNames(id, flag, popMsg) {
	var object = document.getElementById(id);
	var s = object.value;
	var rtn = false;
	var pattern = /^[a-zA-Z0-9_\-.]*$/;
	if(s!=null && ""!=s) {
		if(s.indexOf(flag) != -1) {
			var arr = s.split(flag);
			if(arr!=null && arr.length>0) {
				for(i=0; i<arr.length; i++) {
					if("" != arr[i]) {
						if (!pattern.exec(arr[i])) {
							rtn = true;
							break;
						}
					}
				}
				if(rtn) {
					alert(popMsg);
					object.focus();
					return false;
				}
			}
		} else {
			if (!pattern.exec(s)) {
				alert(popMsg);
				object.focus();
				return false;
			}
		}
	}
	return true;
}
//校驗object是否是數組
function isArray(object){   
	return (typeof(object.length) != "undefined");
}  

//校驗checkbox是否被勾選，若沒有一項被勾選，則返回false；否則，返回true
function checkboxNotChecked(name,msg) {
	var object = document.getElementsByName(name);
	if(isArray(object)) {
		var flag = false;
		for(i=0; i<object.length; i++) {
			if(object[i].checked) {
				flag = true;
				break;
			}
		}
		if(!flag) {
			alert(msg);
			return false;
		}
	} else {
		if(!object.checked) {
			alert(msg);
			return false;
		}
	}
	return true;
}
//校驗start必須小於等於end
function isLe(start,end){
	var object1 = document.getElementById(start);
	var object2 = document.getElementById(end);
	if ("" != object1.value && "" != object2.value) {
		if(object1.value <= object2.value){
			return true;
		}else{
			return false;
		}
	}
	return true;
}
//判斷select不為空
function notEmptySelect(sel,popMsg){
	var obj = document.getElementById(sel);
	if (obj.length == 0){
		alert(popMsg);
		return false
	}else{
		return true;
	}
}
//取得系統日期
function getSystemDate(){
	var now = new Date(); //获取系统日期，即Sat Jul 29 08:24:48UTC+0800 2006
	var yy = now.getYear()+""; //截取年，即2006
	var mm = now.getMonth()+ 1 + ""; //截取月，即07
	var dd = now.getDate()+"";//截取日，即29
	if(mm.length<2){
		mm="0"+mm;
	}
	if(dd.length<2){
		dd="0"+dd;
	}
	return yy+"/"+mm+"/"+dd;
}
//返回指定年月最後一天，傳如month=6，實際上是7月
function getLastDay(year,month)   
{   
 var new_year = year;    //取当前的年份   
 var new_month = month;//取下一个月的第一天，方便计算（最后一天不固定）   
 if(month>12)            //如果当前大于12月，则年份转到下一年   
 {   
  new_month -=12;        //月份减   
  new_year++;            //年份增   
 }   
 var new_date = new Date(new_year,new_month,1);                //取当年当月中的第一天   
 var lastDay =  (new Date(new_date.getTime()-1000*60*60*24)).getDate();//获取当月最后一天日期   
 return year+"/"+month+"/"+lastDay;
}   